#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>

int main(int argc, char *argv[])
{
    int status = -1;
    pid_t pid;
    
    pid = fork();
    if (pid == 0)
    { //子进程
        printf("child process, I will sleep 5s\n");
        sleep(5);
        printf("child process, I will exit\n");
        exit(1);
    } 
    else if (pid > 0) 
    { //父进程
        printf("father process, I wait child process exit\n");
        pid = waitpid(pid, &status, 0);  //暂时停止在这里，直到子进程退出，才继续执行
        printf("get child’s process status=0x%x\n", status);
    } 
    else 
    {
        perror("fork\n");
    }

    return 0;
}